package cn.android.support.v7.lib.sin.crown.dialog;

import android.view.MotionEvent;
import android.view.View;
import android.widget.TextView;

import cn.android.support.v7.lib.sin.crown.R;
import cn.android.support.v7.lib.sin.crown.base.BaseApplication;
import cn.android.support.v7.lib.sin.crown.base.BaseDialog;
import cn.android.support.v7.lib.sin.crown.base.BasePhotoActivity;
import cn.android.support.v7.lib.sin.crown.utils.ProportionUtils;

/**
 * Created by 彭治铭 on 2017/9/18.
 */

public class VideoDialog extends BaseDialog {
    private BasePhotoActivity photoActivity;
    private static VideoDialog photoDialog;
    private boolean dismiss = false;


    //PhotoDialog调用BasePhotoActivity里的本地視頻，和拍攝的方法。回調也在BasePhotoActivity里。
    public static VideoDialog getInstance(BasePhotoActivity photoActivity, boolean dismiss) {
        if (isfinish(photoActivity,photoDialog)) {
            photoDialog = new VideoDialog(photoActivity);
        }
        photoDialog.dismiss = dismiss;
        return photoDialog;
    }

    private VideoDialog(BasePhotoActivity photoActivity) {
        this.photoActivity = photoActivity;
        init(photoActivity, R.layout.crown_dialog_video);
        window.setWindowAnimations(R.style.crown_window_bottom);
    }

    TextView crown_txt_photo, crown_txt_camera, crown_txt_cancel;


    @Override
    protected void initUI() {
        crown_txt_photo = (TextView) findViewById(R.id.crown_txt_photo);
        crown_txt_camera = (TextView) findViewById(R.id.crown_txt_camera);
        crown_txt_cancel = (TextView) findViewById(R.id.crown_txt_cancel);
    }

    @Override
    public void adapterUI() {
        ProportionUtils.getInstance().adapterScreen(photoActivity, findViewById(R.id.crown_photo_dialog));
        ProportionUtils.getInstance().adapterTextView(crown_txt_photo);
        ProportionUtils.getInstance().adapterTextView(crown_txt_camera);
        ProportionUtils.getInstance().adapterTextView(crown_txt_cancel);
        ProportionUtils.getInstance().adapterView(findViewById(R.id.crown_guide_line));
        ProportionUtils.getInstance().adapterView(findViewById(R.id.crown_guide));
    }

    @Override
    protected boolean isAutoAdapterUI() {
        return false;
    }

    @Override
    protected boolean isStatus() {
        return true;
    }

    @Override
    protected boolean isTransparent() {
        return false;
    }

    @Override
    protected boolean isLocked() {
        return false;
    }

    @Override
    protected void listener() {
        findViewById(R.id.crown_photo_dialog_bg).setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                if (MotionEvent.ACTION_DOWN == motionEvent.getAction()) {
                    if (dismiss) {
                        dismiss();
                    }
                }
                return true;
            }
        });
        crown_txt_photo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //本地视频
                photoActivity.video();
                dismiss();
            }
        });
        crown_txt_camera.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //拍摄
                photoActivity.cameraVideo();
                dismiss();
            }
        });
        crown_txt_cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //取消
                dismiss();
            }
        });
    }

    @Override
    protected void recycleView() {

    }

    public void setPhotoActivity(BasePhotoActivity photoActivity) {
        this.photoActivity = photoActivity;
    }

    public static void setPhotoDialog(VideoDialog photoDialog) {
        VideoDialog.photoDialog = photoDialog;
    }

    public void setDismiss(boolean dismiss) {
        this.dismiss = dismiss;
    }

    public void setCrown_txt_photo(TextView crown_txt_photo) {
        this.crown_txt_photo = crown_txt_photo;
    }

    public void setCrown_txt_camera(TextView crown_txt_camera) {
        this.crown_txt_camera = crown_txt_camera;
    }

    public void setCrown_txt_cancel(TextView crown_txt_cancel) {
        this.crown_txt_cancel = crown_txt_cancel;
    }
}
